home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPP08.ZIP / MAKETXT.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  1KB  |  57 lines

  1. // maketxt.cpp -- Create a new text file
  2.  
  3. //#include <stream.hpp>
  4. #include <iostream.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. /* -- Function prototypes */
  10.  
  11. void error(const char *message);
  12. void instruct(void);
  13.  
  14. main(int argc, char *argv[])
  15. {
  16.   FILE *fp;
  17.   char s[129];
  18.  
  19.   if (argc == 1) instruct();
  20.   cout << "\nCreating file " << argv[1];
  21.   cout << "\nEnter a blank line to end\n\n";
  22.   fp = fopen(argv[1], "w");
  23.   if (!fp) error("Creating file");
  24.   while (strlen(gets(s)) > 0) {
  25.     fputs(s, fp);
  26.     fputc('\n', fp);
  27.   }
  28.   fclose(fp);
  29. }
  30.  
  31. /* -- Display error message and exit */
  32.  
  33. void error(const char *message)
  34. {
  35. //  cout << form("\n\nERROR: %s\n\n", message);
  36.   printf("\n\nERROR: %s\n\n", message);
  37.   exit(1);
  38. }
  39.  
  40. /* -- Display instructions and exit */
  41.  
  42. void instruct(void)
  43. {
  44.   cout << "\nMAKETXT <filename>";
  45.   cout << "\nInstructions: Enter a file name, then type";
  46.   cout << "\nlines of text. End with a blank line. Note:";
  47.   cout << "\nan existing <filename> will be erased!\n";
  48.   exit(1);
  49. }
  50.  
  51.  
  52. // Copyright (c) 1990 by Tom Swan. All rights reserved
  53. // Revision 1.00    Date: 10/06/1990   Time: 02:14 pm
  54.  
  55. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  56. // Converted for Borland C++ 2.0
  57.